package com.manning.s2ip.interceptors;

import javax.sql.DataSource;

import org.apache.commons.dbcp.BasicDataSource;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.MethodFilterInterceptor;

public class DataSourceStatsLogger extends MethodFilterInterceptor {

	private DataSource dataSource;
	
	@Override
	protected String doIntercept(ActionInvocation invocation) throws Exception {
		String returnCode = invocation.invoke();
		BasicDataSource bds = (BasicDataSource) dataSource;
		log.info("Data Source stats: Active - " + bds.getNumActive() + 
				", Idle - " + bds.getNumIdle() + 
				", Max Active - " + bds.getMaxActive() + 
				", Min Idle - " + bds.getMinIdle() );
		return returnCode;
		
	}

	public void setDataSource(DataSource dataSource) {
		this.dataSource = dataSource;
	}
}
